# define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;

const int MAXN = 100001;

int arr[MAXN];
int help[MAXN];

int n;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    while (cin >> n) {
        for (int i = 0; i < n; i++) {
            cin >> arr[i];
        }

        cout << smallSum(0, n - 1) << endl;
    }

    return 0;
}

long long smallSum(int l, int r) {
    if (l == r) return 0;

    int m = (l + r) >> 1;
    return smallSum(l, m) + smallSum(m + 1, r) + merge(l, m, r);
}

long long merge(int l, int m, int r) {
    long long ans = 0;

    for (int j = m + 1, i = l, sum = 0; j <= r; j++) {
        while (i <= m && arr[i] <= arr[j]) {
            sum += arr[i++];
        }
        ans += sum;
    }

    int i = l;
    int a = l, b = m + 1;
    while (a <= m && b <= r) {
        help[i++] = arr[a] <= arr[b] ? arr[a++] : arr[b++];
    }

    while (a <= m) help[i++] = arr[a++];
    while (b <= r) help[i++] = arr[b++];

    for (i = l; i <= r; i++) {
        arr[i] = help[i];
    }

    return ans;
}